import numpy as np

class ObjectTable(object):
    def __init__(self, table):
        self.table = table
        self.vals = self.table[:,1]
        self.costs = self.table[:,0]
        self.n = len(self.table) # the number of object in table
    def evalVals(self, X):
        #X is a list, and x_i is the number that you put object i into knapsack
        valSum = 0
        index = 0
        #cal sum
        for x in X:
            valSum += x*self.vals[index] # sum of x_i * v_i 
            index += 1
        return valSum
    def evalCosts(self, X):
        costSum = 0
        index = 0
        for x in X:
            costSum += x*self.costs[index] #sum of x_i * w_i
            index += 1
        return costSum
    def totalVals(self):
        return self.vals.sum()
    def totalCosts(self):
        return self.costs.sum()
'''
table = np.loadtxt("table.csv",int)
print(table)
T = ObjectTable(table)
print(T.evalVals([0,0,0,1,1]))
print(T.evalCosts([0,0,0,1,1]))
'''
